using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace CincinnatiLibraryRenew
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            User[] users;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length == 0)
            {
                users = GetConfiguration();
                if (users.Length == 0)
                {
                    users = new User[1];
                    LoginForm lf = new LoginForm();
                    if (DialogResult.OK == lf.ShowDialog())
                        users[0] = lf.user;
                    else return;
                }
            }
            else
            {
                users = new User[1];
                users[0] = new User(args);
            }
            
            //Application.Run(new Form1(users[0]));
            foreach(User u in users)
            {
                u.StartRenewingItems();
            }
        }

        private static User[] GetConfiguration()
        {
            List<User> stringList = new List<User>(1);
            StreamReader sr = new StreamReader("config.txt");
            string[] tempArray;
            string temp;
            while ((temp = sr.ReadLine())!= null)
            {
                temp = temp.Trim();
                if (temp.StartsWith("#") || temp.StartsWith("//"))
                    continue;
                tempArray = temp.Split(',');
                if (tempArray.Length > 1)
                    stringList.Add(new User(tempArray));
            }
            return stringList.ToArray();
        }
    }
}